import QtQuick 2.12
import QtQuick.Window 2.12
import QtWebEngine 1.8
import QtQuick.Controls 2.5

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Welcome")
    property string wUrl
    property string webUrl

    Row {
        id: row
        width: 640
        height: 63

        Label {
            id: label
            text: qsTr("input a url:")
        }

        TextField {
            id: textField
            placeholderText: qsTr("Text Field")
            text:wUrl
        }

        Button {
            id: button
            text: qsTr("open url")
            onClicked: {
               // myWebView.webUrl = "http://" + textField.text
                webUrl = "http://" + textField.text
                console.debug(textField.text)
            }
        }

        Button {
            id: button1
            text: qsTr("back")
            onClicked: myWeb.action(myWeb.Back).trigger()
            enabled: myWeb.action(myWeb.Back).enabled

        }

        Button {
            id: button2
            text: qsTr("forward")
            onClicked: myWeb.action(myWeb.Forward).trigger()
            enabled: myWeb.action(myWeb.Forward).enabled
        }


    }

    Row {
        id: row1
        x: 0
        y: 63
        width: parent.width
        height: parent.height

//        MyWebView {
//            id: myWebView
//            anchors.fill: parent

//        }
        WebEngineView {
            id :myWeb
            anchors.fill: parent
            url:webUrl
            settings.pluginsEnabled:true
            settings.javascriptEnabled: true
           //WebEngineAction.trigger: canGoBack

            onUrlChanged: {
                console.log("url 1: " +url)
                wUrl = url
            }

            //鼠标点击响应
            onNewViewRequested: {

                url = request.requestedUrl
                console.log("url 2: " +url)
            }

            //滑过即可响应
    //        onLinkHovered: {
    //           url = hoveredUrl
    //           console.log("url 3: " +url)
    //        }

            //WebDataComponent
    //        MouseArea {

    //              anchors.fill: parent
    //              drag.target: parent.data

    //         }


        }


    }





}
